#include "PrecompiledHeaders.h"
#include "Game.h"

#if WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"

INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
{
  char **argv;
  int argc = 1;
  
  char *token;
  
  //determine number of arguments
  token = strtok (strCmdLine," ");
  while (token != NULL)
  {
    argc++;
    token = strtok (NULL, " ");
  }
  argv = new char* [argc];
  
  //fill argument array
  token = strtok (strCmdLine," ");
  int i=1;
  while (token != NULL)
  {
    argv[i] = token;
    token = strtok (NULL, " ");
    i++; 
  }

#else
int main(int argc, char **argv)
{
#endif
	Game* game = NULL;
	try
	{
	    bool pod_control = false, pod_config_file = false;
        int i;
        
        srand ( time(NULL) );
        
	    for (i = 1; i < argc; i++)
	    {
	        Ogre::String arg(argv[i]);
	        if (arg == "-pod")
	            pod_control = pod_config_file = true;
	        else if (arg == "-pod-control")
	            pod_control = true;
	        else if (arg == "-pod-config-file")
	            pod_config_file = true;
	    }
		game = new Game(pod_control, pod_config_file);
		// initialise the game
		game->start();
	}
	catch (Ogre::Exception& e)
	{
        std::cout << "An exception has occured: " << e.getFullDescription() << std::endl;
 	}

	delete game;

	return 0;
}
